﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="Payer", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(Payer))]
    public class PayerSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IPayer clazz;
        
        public PayerSerializer(IPayer clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("Name");
            if (clazz.Name!=null) {
                Writer.WriteTypeAttribute("http://producers.arireg.xtee.riik.ee/producer/arireg", ">>Payer>Name");
                Writer.WriteString(clazz.Name.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Name");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("RegNum");
            if (clazz.RegNum!=null) {
                Writer.WriteTypeAttribute("http://producers.arireg.xtee.riik.ee/producer/arireg", ">>Payer>RegNum");
                Writer.WriteString(clazz.RegNum.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : RegNum");
            }
            Writer.WriteEndElement();
            if (clazz.AccountNum!=null) {
                Writer.WriteStartElement("AccountNum");
                Writer.WriteTypeAttribute("http://producers.arireg.xtee.riik.ee/producer/arireg", ">>Payer>AccountNum");
                Writer.WriteString(clazz.AccountNum.ToString());
                Writer.WriteEndElement();
            }
            if (clazz.RefNum!=null) {
                Writer.WriteStartElement("RefNum");
                Writer.WriteTypeAttribute("http://producers.arireg.xtee.riik.ee/producer/arireg", ">>Payer>RefNum");
                Writer.WriteString(clazz.RefNum.ToString());
                Writer.WriteEndElement();
            }
            if (clazz.TransmissionDate!=null) {
                Writer.WriteStartElement("TransmissionDate");
                Writer.WriteTypeAttribute("http://producers.arireg.xtee.riik.ee/producer/arireg", ">>Payer>TransmissionDate");
                Writer.WriteString(clazz.TransmissionDate.ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
        START:
            if ((Reader.LocalName == "Name")) {
                goto Name;
            }
            else {
                if ((Reader.LocalName == "RegNum")) {
                    goto RegNum;
                }
                else {
                    if ((Reader.LocalName == "AccountNum")) {
                        goto AccountNum;
                    }
                    else {
                        if ((Reader.LocalName == "RefNum")) {
                            goto RefNum;
                        }
                        else {
                            if ((Reader.LocalName == "TransmissionDate")) {
                                goto TransmissionDate;
                            }
                            else {
                                return;
                            }
                        }
                    }
                }
            }
        Name:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Payer>Name");
            }
            clazz.Name = new Payer.NameType(Reader.ReadElementString("Name"));
            goto START;
        RegNum:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Payer>RegNum");
            }
            clazz.RegNum = new Payer.RegNumType(Reader.ReadElementString("RegNum"));
            goto START;
        AccountNum:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Payer>AccountNum");
            }
            clazz.AccountNum = new Payer.AccountNumType(Reader.ReadElementString("AccountNum"));
            goto START;
        RefNum:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Payer>RefNum");
            }
            clazz.RefNum = new Payer.RefNumType(Reader.ReadElementString("RefNum"));
            goto START;
        TransmissionDate:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Payer>TransmissionDate");
            }
            clazz.TransmissionDate = new Payer.TransmissionDateType(Reader.ReadElementString("TransmissionDate"));
            goto START;
        }
    }
}
